﻿using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace BaseUi
{
    public class ChannelViewModel : BindableBase
    { /// <summary>
      /// 数据库SN
      /// </summary>
        public string SQLSN;
        /// <summary>
        /// 视觉SN
        /// </summary>
        public string VisionSN;
        /// <summary>
        /// OKNG
        /// </summary>
        public string okng;
        /// <summary>
        /// 弹窗提示
        /// </summary>
        public string mag;
        /// <summary>
        /// 弹窗提示
        /// </summary>
        public string Mag { get => mag; set { SetProperty(ref mag, value); } }
        /// <summary>
        /// 坐标顺序
        /// </summary>
        public  string num;
        //public string Num { get => num; set { SetProperty(ref num, value); } }
        private string code;
        /// <summary>
        /// 状态(颜色)
        /// </summary>
		public string Code { get => code; set { SetProperty(ref code, value); } }
        /// <summary>
        /// 控件处理数据，进行视觉确认，视觉与数据库信息不符的报错
        /// </summary>
        /// <param name="sqlSN">数据库的编码</param>
        /// <param name="visionSN">视觉获取的编码</param>
        /// <param name="okng">数据库是否应该丢弃</param>
        /// <param name="ml">模拟状态不对比编码</param>
        internal void check(string sqlSN,string ONNG, string visionSN, bool ml)
        {
            try
            {
                if (ONNG==null)
                {
                    ONNG="NULL";
                }
                if (sqlSN!=SQLSN|| ONNG!= okng)
                {
                    Mag = $"位置{num}\r\n数据库异，常入tray盘页面{SQLSN}，{okng}；数据库{sqlSN}，{ONNG}";
                    Code = "NG";
                    return;
                }
                VisionSN = visionSN;
                Mag = $"位置{num}\r\n编码{SQLSN}";
                if (okng==""||SQLSN==""||okng==null)
                {
                    Mag = $"位置{num}\r\n没有数据库信息";
                    Code = "NG";
                    return;
                }
                //Code = "OK";
                //return;
                if (okng=="OK")
                {
                    if (VisionSN=="")
                    {
                        Mag = $"位置{num}\r\n视觉为空错误，编码{SQLSN}，状态{okng}";
                        Code = "NG";
                        return;
                    }
                    if (!ml)
                    {
                        if (SQLSN != VisionSN)
                        {
                            Mag = $"位置{num}\r\n视觉编码{VisionSN}不一致错误，编码{SQLSN}，状态{okng}";
                            Code = "NG";
                            return;
                        }
                    }
                }
                else
                {
                    if (VisionSN!="")
                    {
                        Mag = $"位置{num}\r\n视觉编码{VisionSN}不为空错误，编码{SQLSN}，状态{okng}，";
                        Code = "NG";
                        return;
                    }
                    else
                    {
                        Mag = $"位置{num}\r\n确认，编码{SQLSN}，状态{okng}视觉为空";
                        Code = "空";
                        return;
                    }
                }
                Mag = $"位置{num}\r\n确认，编码{SQLSN}，状态{okng}";
                Code = "OK";

            }
            catch (Exception ee)
            {
                Code = "NG";
                Mag = $"位置{num}\r\n{ee.ToString()}";
            }
        }
        /// <summary>
        /// 将产品放入tray盘
        /// </summary>
        /// <param name="sqlSN"></param>
        /// <param name="OKNG"></param>
        internal void adddata(string sqlSN, string OKNG)
        {
            try
            {
                SQLSN = sqlSN;
                if (OKNG==null||OKNG=="")
                {
                    okng = "NULL";
                }
                else
                {
                    okng = OKNG;
                }
                
                Code = "就绪";

            }
            catch (Exception ee)
            {
                Code = "NG";
                Mag = $"位置{num}\r\n{ee.ToString()}";
            }
        }
    }
}
